package com.haozi.core;

import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiRobotSendRequest;
import com.dingtalk.api.response.OapiRobotSendResponse;
import com.haozi.config.GlobalConfig;
import com.haozi.constants.ConfigConstant;
import com.haozi.dto.PointResult;
import com.haozi.event.GetPointAfterEvent;
import com.haozi.exception.SystemException;
import com.taobao.api.ApiException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.Arrays;

/**
 * @author zyh
 * @version 1.0
 * @date 2022/4/27 11:41 上午
 */
@Component
@Slf4j
public class DingDingDataHandler {


    @Autowired
    GlobalConfig globalConfig;

    public void sendMesg(String title,String message){

        String dingUrl= globalConfig.getProperties(ConfigConstant.DING_TALK_URL);

        if(StrUtil.isBlank(dingUrl)){
            throw new SystemException("钉钉地址配置错误");
        }
        DingTalkClient client = new DefaultDingTalkClient(dingUrl);
        OapiRobotSendRequest request = new OapiRobotSendRequest();
        request.setMsgtype("text");
        OapiRobotSendRequest.At at = new OapiRobotSendRequest.At();
        at.setIsAtAll(true);
        request.setAt(at);
        request.setMsgtype("link");

        request.setMsgtype("markdown");
        OapiRobotSendRequest.Markdown markdown = new OapiRobotSendRequest.Markdown();
        markdown.setTitle(title);
        markdown.setText(message);
        request.setMarkdown(markdown);
        try {
            OapiRobotSendResponse response = client.execute(request);
        } catch (ApiException e) {
            e.printStackTrace();
        }


    }
}
